Why isn't the JavaScript find method returning the expected result compared to foreach